package com.twobu.twobuinsight.security;

import com.twobu.twobuinsight.entity.User;
import lombok.Data;
import java.io.Serializable;

/**
 * 用户上下文，存储当前登录用户信息
 */
@Data
public class UserContext implements Serializable {

    private static final long serialVersionUID = 1L;

    private Long id;
    private Long userId;
    private String username;
    private String roleId;
    private Integer tenantId;

    public static UserContext fromUser(User user) {
        UserContext userContext = new UserContext();
        userContext.setId(user.getId());
        userContext.setUserId(user.getUserId());
        userContext.setUsername(user.getUsername());
        userContext.setRoleId(user.getRoleId());
        userContext.setTenantId(user.getTenantId());
        return userContext;
    }
}
